﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BySoft.Web.Utility;
using System.Data;
using BySoft.Server.Common.Schema;

namespace BySoft.Web.Site
{//BySoft.Web.Site.MastePage
    public partial class Default : BasePage
    {
        string menuid = "";

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override void OnLoadComplete(EventArgs e)
        {
            base.OnLoadComplete(e);
            menuid = UIHelper.GetQueryStringValue("menu");
            if (!String.IsNullOrEmpty(menuid))
            {
                if (CheckLogin())
                {
                    DataTable dtLeftMenulist = (DataTable)Session["LeftModulelist"];
                    DataRow[] drs = dtLeftMenulist.Select("PARENTMODULEID='" + menuid + "'", "ORDERNO");

                    ((BySoft.Web.Site.MastePage.EmptyMaster)this.Master.Master).Body.Attributes["onload"] = "showFirstTopmenu('" + menuid + "','" + (drs.Length > 0 ? drs[0]["FUNCTIONURL"].ToString() : "") + "')";
                }
                else
                {
                    ((BySoft.Web.Site.MastePage.EmptyMaster)this.Master.Master).Body.Attributes["onload"] = "window.location = 'Login.aspx'";
                }
            }
            else
            {
                bool bHaveFirstPage = false;
                DataTable dtTopMenulist = (DataTable)Session["TopModulelist"];
                if (dtTopMenulist != null && dtTopMenulist.Rows.Count > 0 && dtTopMenulist.Rows[0]["MODULEID"] != null)
                {
                    menuid = dtTopMenulist.Rows[0]["MODULEID"].ToString();
                    DataRow[] rows = dtTopMenulist.Select(string.Format("ModuleID='{0}'", "FS01"));
                    if (rows.Length > 0)
                    {
                        bHaveFirstPage = true;
                    }
                }

                if (CheckLogin())
                {
                    DataTable dtLeftMenulist = (DataTable)Session["LeftModulelist"];
                    DataRow[] drs = dtLeftMenulist.Select("PARENTMODULEID='" + menuid + "'", "ORDERNO");

                    if (bHaveFirstPage)
                    {
                        ((BySoft.Web.Site.MastePage.EmptyMaster)this.Master.Master).Body.Attributes["onload"] = "showFirstTopmenu('FS01','Main.aspx')";
                    }
                    else
                    {
                        ((BySoft.Web.Site.MastePage.EmptyMaster)this.Master.Master).Body.Attributes["onload"] = "showFirstTopmenu('" + menuid + "','" + (drs.Length > 0 ? drs[0]["FUNCTIONURL"].ToString() : "") + "')";
                    }

                }
                else
                {
                    ((BySoft.Web.Site.MastePage.EmptyMaster)this.Master.Master).Body.Attributes["onload"] = "window.location = 'Login.aspx'";
                }
            }

        }
    }
}
